/*
 * Licensed to the Tai Ping Jin Ke
 *
 * Copyright (c) 2022 .
 * All rights reserved.
 * 项目名称：登录通-数据源-数据持久层
 * 版权说明：本软件属太平金融科技服务(上海)有限公司所有，在未获得太平金融科技服务(上海)有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.taiping.dlt.dao;

import com.taiping.dlt.repository.IRepository;
import com.taipingframework.boot.es.facade.ReactorElasticAccess;
import io.jsonwebtoken.lang.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Stream;

/**
 * 数据访问对象 - 用户登录
 *
 * @param <DO> 数据访问对象
 */
public abstract class DataAccessObject<DO extends Object & Serializable> implements IRepository<DO> {

    @Autowired
    protected ReactorElasticAccess reactorElasticAccess;

    @Override
    public Mono<DO> queryForObject(String objectId) {
        return Mono.empty();
    }

    @Override
    public Flux<DO> queryForList(DO object) {
        return Flux.fromStream(Stream.of(object));
    }

    @Override
    public Mono<Boolean> update(DO object) {
        return Mono.create(sink -> sink.success(false));
    }

    @Override
    public Flux<DO> batchInsert(List<DO> recordList) {
        return Flux.fromIterable(recordList);
    }

    @Override
    public Mono<Boolean> batchDelete(List<String> objectIdList) {
        return Mono.fromSupplier(() -> !Collections.isEmpty(objectIdList));
    }

}
